package com.bytezreo.duotai2;

//多态性的使用 举例一
public class AnimalTest
{
	public static void main(String[] args) 
	{
		AnimalTest test = new AnimalTest();
		test.func(new Dog());
		
		
		test.func(new Cat());
		
		
	}
	
	//声明是 animal          Animal animal = new Dog();
	public void func(Animal animal)
	{
		animal.eat();
		animal.shout();
		
		if(animal instanceof Dog )
		{
			Dog d = (Dog)animal;
			d.watchDoor();
		}
		
		
		
	}
	
	
	
	//没有多态性的时候
//	public void func(Dog dog)
//	{
//		dog.eat();
//		dog.shout();
//	}
//	
//	public void func(Cat cat)
//	{
//		cat.eat();
//		cat.shout();
//	}
//	
//	
	
}

class Animal
{
	public void eat()
	{
		System.out.println("动物：进食");
	}
	public void shout()
	{
		System.out.println("动物：叫");
	}
	
	
	
	
	
}

class Dog extends Animal
{
	public void eat()
	{
		System.out.println("狗：吃骨头");
	}
	public void shout()
	{
		System.out.println("狗：汪汪汪");
	}
	
	public void watchDoor()
	{
		System.out.println("看门");
	}
}



class Cat extends Animal
{
	public void eat()
	{
		System.out.println("猫：吃大鱼");
	}
	public void shout()
	{
		System.out.println("猫：喵喵喵");
	}
}

//举例二

class Order
{
	public void method(Object obj)
	{
		
	}
}









































